﻿using Mathmall.Administration.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Mathmall.Administration.Data
{
    public class CategoryEntityTypeConfiguration : IEntityTypeConfiguration<Category>
    {
        public void Configure(EntityTypeBuilder<Category> builder)
        {
            // 不使用output子句
            builder.ToTable(table => table.UseSqlOutputClause(false));

            builder
                .ToTable(nameof(Category))
                .ToTable(tableBuilder => tableBuilder.HasComment("商品三级分类"));

            builder
                .HasKey(category => category.CategoryID)
                .HasName("CategoryID");

            builder
                .Property(category => category.Name)
                .HasColumnName("Name")
                .HasColumnType("nvarchar(50)")
                .HasComment("分类名称")
                .IsRequired();

            builder
                .Property(category => category.ParentCID)
                .HasColumnName("ParentCID")
                .HasColumnType("int")
                .HasComment("父分类id")
                .IsRequired(true);

            builder
                .Property(category => category.CatLevel)
                .HasColumnName("CatLevel")
                .HasColumnType("int")
                .HasComment("层级")
                .IsRequired(false);

            builder
                .Property(category => category.ShowStatus)
                .HasColumnName("ShowStatus")
                .HasColumnType("bit")
                .HasComment("是否显示[0-不显示，1显示]")
                .IsRequired(false);

            builder
                .Property(category => category.Sort)
                .HasColumnName("Sort")
                .HasColumnType("int")
                .HasComment("顺序")
                .IsRequired(false);

            builder
                .Property(category => category.Icon)
                .HasColumnName("Icon")
                .HasColumnType("varchar(255)")
                .HasComment("图标地址")
                .IsRequired(false);

            builder
                .Property(category => category.ProductUnit)
                .HasColumnName("ProductUnit")
                .HasColumnType("nvarchar(50)")
                .HasComment("计量单位")
                .IsRequired(false);

            builder
                .Property(category => category.ProductCount)
                .HasColumnName("ProductCount")
                .HasColumnType("int")
                .HasComment("商品数量")
                .IsRequired(false);

            builder
                .Property(category => category.CreateTime)
                .HasColumnName("CreateTime")
                .HasColumnType("datetime")
                .HasComment("创建时间")
                .IsRequired(false);

            builder
                .Property(category => category.LastUpdateTime)
                .HasColumnName("LastUpdateTime")
                .HasColumnType("datetime")
                .HasComment("最后更新时间")
                .IsRequired(false);
        }
    }
}